#ifndef __TYPE_DEF_LINUX__
#define __TYPE_DEF_LINUX__

#include <bits/stdint-intn.h>
#include <bits/stdint-uintn.h>
#include <stdint.h>
#include <sys/types.h>

/* return status values */

/* storage class specifier definitions */

#define FAST   register
#define IMPORT extern
#define LOCAL  static

#if !defined( __cplusplus )

#ifndef max
#define max( x, y ) ( ( ( x ) < ( y ) ) ? ( y ) : ( x ) )
#endif

#ifndef min
#define min( x, y ) ( ( ( x ) < ( y ) ) ? ( x ) : ( y ) )
#endif

#endif /* !__cplusplus */
#define OK    0
#define ERROR ( -1 )

#if !defined( FALSE ) || ( FALSE != ( 0 ) )
#define FALSE ( 0 )
#endif

#if !defined( TRUE ) || ( TRUE != ( 1 ) )
#define TRUE ( 1 )
#endif

typedef uint32_t UINT;
typedef u_long   ULONG;
typedef int32_t  BOOL;
typedef uint8_t  UCHAR;
typedef UINT     WNCAN_ChannelMode;
#define WNCAN_MAX_DATA_LEN 8

/**********ioctl define  *****************/
#define FIOOPTIONS    3          /* set options (FIOSETOPTIONS) */
#define FIOBAUDRATE   4          /* set serial baud rate */
#define FIONWRITE     12         /* get num chars still to be written */
#define FIOSETOPTIONS FIOOPTIONS /* set options */

/** serial port options */
#define OPT_ECHO     0x01 /* echo input */
#define OPT_CRMOD    0x02 /* lf -> crlf */
#define OPT_TANDEM   0x04 /* ^S/^Q flow control protocol */
#define OPT_7_BIT    0x08 /* strip parity bit from 8 bit input */
#define OPT_MON_TRAP 0x10 /* enable trap to monitor */
#define OPT_ABORT    0x20 /* enable shell restart */
#define OPT_LINE     0x40 /* enable basic line protocol */

#define OPT_RAW      0 /* raw mode */
/* ==== WNCAN DevIO interface ioctl() commands ==== */
/* Base command code */
#define DEVIO_CANCMD_BASE 100
/* Device commands */

#define WNCAN_HALT       ( DEVIO_CANCMD_BASE + 1 )
#define WNCAN_RXCHAN_GET ( DEVIO_CANCMD_BASE + 5 )
#define WNCAN_TXCHAN_GET ( DEVIO_CANCMD_BASE + 6 )
/* Channel commands */

#define WNCAN_CHNCONFIG_SET ( DEVIO_CANCMD_BASE + 12 )
#define WNCAN_CHNCONFIG_GET ( DEVIO_CANCMD_BASE + 13 )
#define WNCAN_CHN_ENABLE    ( DEVIO_CANCMD_BASE + 14 )

/*
   CAN channel options
   Used in flags field of WNCAN_CHNCONFIG struct
*/

#define WNCAN_CHNCFG_NONE      0x000 /* selects no elements */
#define WNCAN_CHNCFG_CHANNEL   0x100 /* selects channel information only */
#define WNCAN_CHNCFG_LCLFILTER 0x200 /* selects local filter only */

/* serial device I/O controls */

#define SIO_BAUD_SET    0x1003
#define SIO_BAUD_GET    0x1004

#define SIO_HW_OPTS_SET 0x1005
#define SIO_HW_OPTS_GET 0x1006
/* options to SIO_HW_OPTS_SET (ala POSIX), bitwise or'ed together */

#define CLOCAL 0x1 /* ignore modem status lines */
#define CREAD  0x2 /* enable device reciever */

#define CSIZE  0xc /* bits 3 and 4 encode the character size */
#define CS5    0x0 /* 5 bits */
#define CS6    0x4 /* 6 bits */
#define CS7    0x8 /* 7 bits */
#define CS8    0xc /* 8 bits */

#define HUPCL  0x10 /* hang up on last close */
#define STOPB  0x20 /* send two stop bits (else one) */
#define PARENB 0x40 /* parity detection enabled (else disabled) */
#define PARODD 0x80 /* odd parity  (else even) */

/**** */
typedef struct _wncan_chnconfig {
  UINT flags; /* access options */
  /* local filter mask */
  struct {
    ULONG mask;     /* filter mask */
    BOOL  extended; /* extended flag */
  } filter;
  struct {
    ULONG id;                       /* CAN ID */
    BOOL  extId;                    /* is ID extended or not? */
    UCHAR len;                      /* length */
    UCHAR data[WNCAN_MAX_DATA_LEN]; /* message data */
  } channel;

  BOOL              rtr;  /* RTR bit setting */
  WNCAN_ChannelMode mode; /* channel mode */
} WNCAN_CHNCONFIG;
typedef struct _wncan_chnmsg {
  ULONG id;                       /* CAN ID */
  BOOL  extId;                    /* is ID extended or not? */
  BOOL  rtr;                      /* remote frame transmit request */
  UCHAR len;                      /* message length */
  UCHAR data[WNCAN_MAX_DATA_LEN]; /* message data */
} WNCAN_CHNMSG;

/*****function only in vxworks */
extern uint32_t taskDelay( uint32_t ticks );
extern int32_t  errnoGet( void );
#endif
